/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd.            */
/*                                                                 */
/*  NAME      = t_sqlserver_destroy_session.c                      */
/*  NOTE      =                                                    */
/*  DATE      = 2014/12/09 by geyh                                 */
/*******************************************************************/

#include <stdio.h>
#include <string.h>
#include <CUnit/Basic.h>

#include <frcomm.h>
#include <sqlserver/config.h>
#include <sqlserver/sqlserver_core.h>
#include <sqlserver/sqlserver_common.h>

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

static void __case1(void)
{
    L7session_sqlserver **pp_st_session;
    pp_st_session = NULL;

    sqlserver_destroy_session(pp_st_session);

    return;
}

static void __case2(void)
{
    L7session_sqlserver *p_st_session;
    p_st_session = NULL;

    sqlserver_destroy_session(&p_st_session);

    return;
}

static void __case3(void)
{
    L7session_sqlserver *p_st_session = NULL;
    char *p_char_tmp = NULL;

    p_st_session = (L7session_sqlserver *) frmalloc(sizeof(L7session_sqlserver));

    //p_cli_host_user
    p_char_tmp = (char *) frmalloc(strlen("p_cli_host_user") + 1);
    snprintf(p_char_tmp, strlen("p_cli_host_user") + 1, "%s", "p_cli_host_user");
    p_st_session->p_cli_host_user = p_char_tmp;

    //p_program
    p_char_tmp = (char *) frmalloc(strlen("p_program") + 1);
    snprintf(p_char_tmp, strlen("p_program") + 1, "%s", "p_program");
    p_st_session->p_program = p_char_tmp;

    //p_db_name
    p_char_tmp = (char *) frmalloc(strlen("p_db_name") + 1);
    snprintf(p_char_tmp, strlen("p_db_name") + 1, "%s", "p_db_name");
    p_st_session->p_db_name = p_char_tmp;

    //p_db_user
    p_char_tmp = (char *) frmalloc(strlen("p_db_user") + 1);
    snprintf(p_char_tmp, strlen("p_db_user") + 1, "%s", "p_db_user");
    p_st_session->p_db_user = p_char_tmp;

    //p_db_user
    p_char_tmp = (char *) frmalloc(strlen("p_tds_charset") + 1);
    snprintf(p_char_tmp, strlen("p_tds_charset") + 1, "%s", "p_tds_charset");
    p_st_session->p_tds_charset = p_char_tmp;

    sqlserver_destroy_session(&p_st_session);

    CU_ASSERT_PTR_NULL(p_st_session);

    frfree(p_st_session);

    return;
}

int add_suite_sqlserver_destroy_session(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" sqlserver_destroy_session()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    //增加测试用例
    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
